@extends('admin.layout')
@section('title','版本列表')
@section('body')


    <table class="layui-table " lay-even lay-skin="line">
        <colgroup>

        </colgroup>
        <thead>
        <tr>
            <th>更新名称</th>
            <th>版本号</th>
            <th>最新文件路径</th>
            <th>更新说明</th>
            <th>更新类型</th>
            <th>删除</th>
        </tr>
        </thead>
        <tbody>
        @foreach($app as $value)
            <tr id="tr{{$value->id}}">
                <td>{{$value->name}}</td>
                <td>{{$value->version}}</td>
                <td>{{$value->app_path}}</td>
                <td>{{$value->detail}}</td>
                <td>{{$value->type==1?"增量":"整包"}}</td>
                <td>
                    <button onclick="del({{$value->version_id}});" class="layui-btn-small layui-btn">
                        删除
                    </button>
                </td>
            </tr>
        @endforeach
        </tbody>
    </table>
    <button class="layui-btn layui-btn-small" onclick="ins()">添加最新版本</button>


@endsection
@section('js')
    <div id="ins_form" style="display: none">
        <form class="layui-form" id="form" action="" method="post" enctype="multipart/form-data">
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="" name="name"  lay-verify="required" placeholder="请输入更新名称" autocomplete="off" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">版本号</label>
                <div class="layui-input-inline">
                    <input type="text" id="" name="version"  lay-verify="required" placeholder="请输入版本号" autocomplete="off" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">安卓安装包地址</label>
                <div class="layui-input-inline">
                    <input type="file" id="" name="app_file"  lay-verify="required" placeholder="请输入安装包地址" autocomplete="off" class="layui-field-box ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">IOS安装包地址</label>
                <div class="layui-input-inline">
                    <input type="text" id="" name="app_ios_path"  lay-verify="required" placeholder="请输入itunes安装包地址" autocomplete="off" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">更新说明</label>
                <div class="layui-input-inline">
                    <input type="text" id="" name="version_detail"  lay-verify="required" placeholder="请输入更新说明" autocomplete="off" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">更新类型</label>
                <div class="layui-input-inline">
                    <input name="type" value="1" title="增量更新" checked="" type="radio">
                    <input name="type" value="2" title="整包升级" type="radio">
                </div>
            </div>
            {{csrf_field()}}
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input  style="margin-left:150px" type="submit" value="提交" class="layui-btn">
                </div>
            </div>

        </form>
    </div>
<script>

    function del(id) {
        layer.confirm('是否确认删除？', {
                btn: ['确定', '取消'] //可以无限个按钮
            },function () {
            layer.load();
            $.post({
                url:'{{url('config/version_del')}}',
                data:{'version_id':id,'_token':'{{csrf_token()}}'},
                success:function (res) {
                    layer.closeAll();
                    if (res.status==1){
                        location.reload();
                        layer.msg('删除成功');

                    }else{
                        location.reload();
                        layer.msg('删除失败');
                    }
                }
            })
        })

    }
    function ins() {
        layui.use('form');
        layer.open({
            title:"添加版本",
            content:$("#ins_form"),
            area: ['500px', '600px'],
            type:1,
            yes:function () {
                $("#form").submit();
            }
        })
    }

</script>
@endsection